package guoanmaker.operator.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.PersonalUserCoupon;

public interface PersonalUserCouponRepository extends JpaRepository<PersonalUserCoupon, String>, JpaSpecificationExecutor<PersonalUserCoupon>{
	@Transactional
	@Modifying
	@Query("UPDATE PersonalUserCoupon set isUsed=1  where id=:id")
	public void updateIsUsedByid(@Param("id")String id);
	
	@Query("select DISTINCT(p.userId)  from PersonalUserCoupon p where p.ocId=:ocId")
	List<String>  findByOcId(@Param("ocId")String ocId);
	
	
	@Query("select count(p.id) from PersonalUserCoupon p where p.ocId=:ocId and p.userId=:userId")
	int  findByOcIdandUserId(@Param("ocId")String ocId,@Param("userId")String userId);
	
}
